package com.ruoyi.platform.enums;


import com.baomidou.mybatisplus.annotation.IEnum;

import java.io.Serializable;
import java.util.Objects;

/**
 * @Author: ES
 * @Date: 2022/8/27 12:52
 * @Description:
 **/
/**
 * @Author: ES
 * @Date: 2022/8/27 12:52
 * @Description:
 **/
public interface BaseEnum<T extends Serializable> extends IEnum<T> {

    Long getCode();

    String desc();

    static <M extends BaseEnum> M getByValue(Class<M> clazz,Serializable value){
        M[] values = clazz.getEnumConstants();
        for (int i = 0, len = values.length; i < len; i++) {
            Serializable v = values[i].getCode();
            if (Objects.equals(v,value)) {
                return values[i];
            }
        }

        return null;
    }
}
